import request from '@/hooks/utils/http'
import { AxiosPromise } from 'axios'

export class  MonitorCacheService {

// 查询缓存详细
    static getCache(): AxiosPromise<CacheVO> {
        return request({
            url: '/monitor/cache',
            method: 'get'
        });
    }

// 查询缓存名称列表
    static listCacheName() {
        return request({
            url: '/monitor/cache/getNames',
            method: 'get'
        });
    }

// 查询缓存键名列表
    static listCacheKey(cacheName: string) {
        return request({
            url: '/monitor/cache/getKeys/' + cacheName,
            method: 'get'
        });
    }

// 查询缓存内容
    static getCacheValue(cacheName: string, cacheKey: string) {
        return request({
            url: '/monitor/cache/getValue/' + cacheName + '/' + cacheKey,
            method: 'get'
        });
    }

// 清理指定名称缓存
    static clearCacheName(cacheName: string) {
        return request({
            url: '/monitor/cache/clearCacheName/' + cacheName,
            method: 'delete'
        });
    }

// 清理指定键名缓存
    static clearCacheKey(cacheName: string, cacheKey: string) {
        return request({
            url: '/monitor/cache/clearCacheKey/' + cacheName + '/' + cacheKey,
            method: 'delete'
        });
    }

// 清理全部缓存
    static clearCacheAll() {
        return request({
            url: '/monitor/cache/clearCacheAll',
            method: 'delete'
        });
    }

}

export interface CacheVO {
    commandStats: Array<{ name: string; value: string }>;

    dbSize: number;

    info: { [key: string]: string };
}
